import request from '@/utils/request'

export function getRoutes() {
  return request({
    url: '/vue-element-admin/routes',
    method: 'get'
  })
}

export function getRoles() {
  return request({
    url: '/vue-element-admin/roles',
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/vue-element-admin/role',
    method: 'post',
    data
  })
}

export function updateRole(id, data) {
  return request({
    url: `/vue-element-admin/role/${id}`,
    method: 'put',
    data
  })
}

export function deleteRole(id) {
  return request({
    url: `/vue-element-admin/role/${id}`,
    method: 'delete'
  })
}

/**
 * 创建菜单
 * @param data
 * @returns {AxiosPromise}
 */
export function create(data) {
  return request({
    url: '/role',
    method: 'post',
    data: data
  })
}

/**
 * id查询菜单
 * @param id
 * @returns {AxiosPromise}
 */
export function findById(id) {
  return request({
    url: '/role/' + id,
    method: 'get'
  })
}

/**
 * pid查询
 * @param id
 * @returns {AxiosPromise}
 */
export function findByPid(id) {
  return request({
    url: '/role/par/' + id,
    method: 'get'
  })
}

/**
 * ids删除菜单
 * @param ids
 * @returns {AxiosPromise}
 */
export function deleteByIds(ids) {
  return request({
    url: '/role',
    method: 'delete',
    data: ids
  })
}

/**
 * 条件查询菜单
 * @param page
 * @param data
 * @returns {AxiosPromise}
 */
export function findAll(page, data) {
  return request({
    url: '/role/search',
    method: 'post',
    params: page,
    data: data
  })
}

/**
 * 查询角色列表
 * @returns {AxiosPromise}
 */
export function findList() {
  return request({
    url: '/role/list',
    method: 'get'
  })
}

/**
 * 角色查询用户
 * @param roleId
 * @returns {AxiosPromise}
 */
export function findUserByRoleId(roleId) {
  return request({
    url: '/role/role/' + roleId,
    method: 'get'
  })
}

/**
 * id更新菜单
 * @param data
 * @returns {AxiosPromise}
 */
export function updateById(data) {
  return request({
    url: '/role',
    method: 'put',
    data: data
  })
}

